home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / For your think c folder / VA Kit ƒ / Explosion.c next >
Encoding:
Text File  |  1992-09-09  |  1.5 KB  |  79 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: Explosion.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Wednesday, September 9, 1992, 21:40
  6.      Created: Thursday, February 9, 1989, 22:35
  7.  
  8.      Copyright © 1989-1992, Juri Munkki
  9. /*/
  10.  
  11. /*
  12. **    Explosion generator
  13. */
  14.  
  15. #undef    _ERRORCHECK_
  16. #define    _NOERRORCHECK_
  17. #include <Math.h>
  18. #include "VA.h"
  19.  
  20. #define    NUMFRAGMENTS 100
  21.  
  22. double    vx[NUMFRAGMENTS];
  23. double    vy[NUMFRAGMENTS];
  24. double    fx[NUMFRAGMENTS];
  25. double    fy[NUMFRAGMENTS];
  26.  
  27. void    CreateNewExplosions()
  28. {
  29.     Handle    Explosion;
  30.     int        *expl;
  31.     double    ang;
  32.     long    size;
  33.     int        i,j,lvl;
  34.     int        fragments;
  35.     
  36.     for(lvl=0;lvl<4;lvl++)
  37.     {    Explosion=GetResource('GNRL',1000+lvl);
  38.         HUnlock(Explosion);
  39.         SetHandleSize(Explosion,65536L);
  40.         HLock(Explosion);
  41.         expl=*(int **)Explosion;
  42.         
  43.         fragments=(lvl+1)*10;
  44.         for(i=0;i<fragments;i++)
  45.         {    do
  46.             {    ang=Random()/100.0;
  47.                 vx[i]=cos(ang)*(lvl+2);
  48.                 vy[i]=sin(ang)*(lvl+2);
  49.                 ang=Random()/100.0;
  50.                 vx[i]*=sin(ang);
  51.                 vy[i]*=sin(ang);
  52.                 fx[i]=3*vx[i];
  53.                 fy[i]=3*vy[i];
  54.             } while(fabs(vx[i]*vx[i]+vy[i]*vy[i])<0.2);
  55.         }
  56.         for(j=fragments;j>(fragments/4);j--)
  57.         {    *expl++=j;
  58.             for(i=0;i<j;i++)
  59.             {    VA.color=5;
  60.                 fx[i]+=vx[i];
  61.                 fy[i]+=vy[i];
  62.                 VASafePixel((int)fx[i]+320,(int)fy[i]+240);
  63.                 *expl++=fx[i];
  64.                 *expl++=fy[i];
  65.                 vy[i]*=0.97;
  66.                 vx[i]*=0.97;
  67.             }
  68.             while(Ticks % 15);
  69.             VADoFrame();
  70.         }
  71.         *expl++=0;
  72.         size=(Ptr)expl-*Explosion;
  73.         HUnlock(Explosion);
  74.         SetHandleSize(Explosion,size);
  75.         ChangedResource(Explosion);
  76.         WriteResource(Explosion);
  77.         ReleaseResource(Explosion);
  78.     }
  79. }